package com.es;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class TestResultSetScrollUpdate {

    public static void main(String[] args) throws SQLException, InterruptedException {

        String sql = "select id,name,id_card,card_no,balance from bank_account";
        Connection connection = JDBCUtils.getConnection("mysql");
        connection.setAutoCommit(false);
        PreparedStatement ps = connection.prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
        ResultSet resultSet = ps.executeQuery();

        //可以滚动怎么看？
        //可以直接定位
        /*
        resultSet.absolute(3);
        System.out.println(resultSet.getString(2)+":"+resultSet.getBigDecimal(5));
        //向上走一行
        resultSet.previous();
        System.out.println(resultSet.getString(2)+":"+resultSet.getBigDecimal(5));
        resultSet.absolute(4);
        Thread.sleep(10000);
        resultSet.next();
        System.out.println(resultSet.getString(2)+":"+resultSet.getBigDecimal(5));

         */
        while(resultSet.next()) {
            resultSet.updateBigDecimal(5, new BigDecimal("8888"));
        }

        connection.commit();


    }
}
